package cj.web.yc.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.yc.domain.Video;

/**
 * 
 * @author 
 *
 */
@DAO
public interface VideoDAO{
	
	@SQL("SELECT a.*,b.descs as categoryIdIn FROM Video a join Category b on a.categoryId=b.id WHERE a.deleteFlag=1 #if(:t.categoryIdIn != null){ AND a.categoryId in (##(:t.categoryIdIn)) } #if(:t.name != null){ AND a.name LIKE '%##(:t.name)%' } ORDER BY a.updateAt DESC LIMIT :t.start,:t.length ")
    List<Video> query(@SQLParam("t") Video video);
	
	@SQL("SELECT count(1) FROM Video WHERE deleteFlag=1 #if(:t.categoryIdIn != null){ AND categoryId in (##(:t.categoryIdIn)) } #if(:t.name != null){ AND name LIKE '%##(:t.name)%' } ")
    int querySize(@SQLParam("t") Video video);
    
    @SQL("SELECT a.*,b.descs as categoryIdIn FROM Video a join Category b on a.categoryId=b.id where a.id=:1")
    Video queryById(int id);
    
    @SQL("INSERT INTO Video (categoryId,name,url,img,status,orderNo,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.categoryId,:t.name,:t.url,:t.img,1,:t.orderNo,1,:t.createUser,now(),:t.updateUser,now()) ")
    void create(@SQLParam("t") Video video);
	
	@SQL("UPDATE Video SET categoryId=:t.categoryId,name=:t.name,url=:t.url,img=:t.img,orderNo=:t.orderNo,updateUser=:t.updateUser,updateAt=now() WHERE id=:t.id ")
    void update(@SQLParam("t") Video video);
    
    @SQL("UPDATE Video SET deleteFlag=0 WHERE id=:1 ")
    void deleteById(int id);
}